package com.foxhorse.androidpractice.activity.kotlin.listview

import android.os.Bundle
import android.widget.Toast
import com.foxhorse.androidpractice.R
import com.foxhorse.androidpractice.activity.BaseActivity
import com.foxhorse.androidpractice.adapter.KotlinListviewAdapter
import com.foxhorse.androidpractice.entity.KotlinEntity
import kotlinx.android.synthetic.main.activity_kotlin_listview.*

class KotlinListViewActivity : BaseActivity() {
    private val TAG = "MainActivity"
    private val list = ArrayList<KotlinEntity>()
    private var adapter: KotlinListviewAdapter? = null
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_kotlin_listview)
        tv_title.setText("第一个使用kotlin开发的界面")
        for (i: Int in 0..9) {
            list.add(KotlinEntity("the ${i.toString()} element"))
        }
        adapter = KotlinListviewAdapter(list, context)
        listview.adapter = adapter
        listview.setOnItemClickListener { _, _, position, _ ->
            Toast.makeText(context, "${list.get(position).des}", Toast.LENGTH_SHORT).show()
        }
        tv_title.setOnClickListener { tv_title.setText("TextView被点击了") }
    }
}
